package com.matt.service.impl;

import com.matt.domain.mp.ParentUser;
import com.matt.domain.mp.WxUser;
import com.matt.repository.AppUserRepository;
import com.matt.repository.ChildrenRepository;
import com.matt.repository.WxUserRepository;
import com.matt.service.WxUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class WxUserServiceImpl implements WxUserService {

    @Autowired
    private ChildrenRepository childrenRepository;

    @Autowired
    private WxUserRepository wxUserRepository;

    @Autowired
    private AppUserRepository appUserRepository;

    @Override
    public List<WxUser> selectWxUserListByChildrenId(String childrenId) {
        //FIXME:  这里需要用家长的手机号码查询
        List<ParentUser> parentUsers = appUserRepository.findAllByCid(childrenId);

        String[] parentIds = parentUsers.stream().filter(o -> StringUtils.isNotEmpty(o.getPhone())).map(o -> {
            return o.getId();
        }).toArray(String[]::new);

        return wxUserRepository.findByParentIdIn(parentIds);
    }
}
